<?
layout("/inc/layout.html",{title:sysTitle}){
?>

<div id="page-wrapper">
	<!--BEGIN TITLE & BREADCRUMB PAGE-->
	<div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
		<div class="page-header pull-left">
			<div class="page-title">个人资料</div>
		</div>
		<ol class="breadcrumb page-breadcrumb pull-left">
			<li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i
				class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li>个人中心&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li class="active">个人资料</li>
		</ol>
		

		<div class="clearfix"></div>
	</div>
	<!--END TITLE & BREADCRUMB PAGE-->
	<!--BEGIN CONTENT-->


	<div class="page-content">

		<div class="row" style="width:auto;">

			<div class="col-lg-12" style="margin-top:-10px; height: 620px;">
				<div class="panel"
					style="height: 620px;width :auto; overflow: auto;">
					<div class="panel ">
						<div class="panel-body pan" style="height:auto">
							<form action="#" class="form-horizontal">
							<div>
								<div class="row" style=" margin:20px 0px 0 0px;">
									<div class="col-md-6" style="width: 45%;">
										<label style="float: left;" for="inputUsername"
											class="col-md-4">用户名 <span class='require'
											id="yonghu">*</span> </label>
										<div class="col-md-12">
											<div class="input-icon">
												<input id="username" disabled="disabled"
													onchange="onPanduan(this.value);" type="text"
													class="form-control" value="" />
											</div>
										</div>
									</div>
									<div class="col-md-6" style="width: 45%; ">
										<label style="float: left;" for="inputUsername"
											class="col-md-4">密码 <span class='require' id="mima">*</span>
										</label>
										<div class="col-md-12">
											<div class="input-icon">
												<input id="password" type="password" class="form-control" />
											</div>
										</div>
									</div>
								</div>
								<div class="row" style=" margin:20px 0px 0 0px;">
									<div class="col-lg-6" style="width: 45%;">
										<label style="float: left;" for="inputUsername" class="col-md-4">昵称 <span
											class='require' id="yonghu">*</span> </label>
										<div class="col-md-12">
											<div class="input-icon">
												<input id="nickname" type="text" class="form-control"
													value="" />
											</div>
										</div>
									</div>
									<div class="col-lg-6" style="width: 45%; ">
										<label style="float: left;" for="inputUsername" class="col-md-4 ">手机号 <span
											class='require'>*</span> </label>
										<div class="col-md-12">
											<div class="input-icon">
												<input id="telephone" type="text" class="form-control" />
											</div>
										</div>
									</div>
								</div>
								<div class="row" style=" margin:20px 0px 0 0px;">
									<div class="col-lg-6" style="width: 45%;">
										<label for="inputUsername" class="col-md-4 ">地址 <span
											class='require' id="yonghu">*</span> </label>
										<div class="col-md-12">
											<div class="input-icon">
												<input id="address" type="text" class="form-control"
													value="" />
											</div>
										</div>
									</div>
									<div class="col-lg-6" style="width: 45%;">
										<label for="inputUsername" class="col-md-4 ">邮箱 <span
											class='require'>*</span> </label>
										<div class="col-md-12">
											<div class="input-icon">
												<input id="email" type="text" class="form-control" />
											</div>
										</div>	
									</div>
								</div>
								<div class="row" style=" margin:20px 0px 0 0px; display: none;" >
									<div class="col-lg-6" style="width: 45%;">
										<label for="inputUsername" class="col-md-4 ">部门名称<span
											class='require'>*</span> </label>
										<div class="col-md-12">
											<div class="input-group input-group-sm mbs">
												<input id="parentclassname" type="text" placeholder="请选择部门"
													class="form-control" disabled="true" /> <span
													class="input-group-btn">
													<button id="xuanze" onclick="saveclassZTree()"
														type="button" data-toggle="dropdown"
														class="btn btn-success dropdown-toggle">选择...</button> </span> <input
													id="parentClassid" type="hidden" value="00"
													class="form-control" />
											</div>
										</div>
									</div>
									<div class="col-lg-6" style="width: 45%;">
										<label for="inputUsername" class="col-md-4 ">用户组名称<span
											class='require'>*</span> </label>
										<div class="col-md-12">
											<div class="input-group input-group-sm mbs">
												<input id="userGroupName" type="text" placeholder="请选择用户组"
													class="form-control" disabled="true" /> <span
													class="input-group-btn">
													<button id="xuanze2" onclick="saveGroupZTree()"
														type="button" data-toggle="dropdown"
														class="btn btn-success dropdown-toggle">选择...</button> </span> <input
													id="userGroupId" type="hidden" value="00"
													class="form-control" />
											</div>
										</div>
									</div>
									<input id="status" type="text" class="form-control"/>
								</div>
								<div class="row" style=" margin:20px 0px 0 0px;">
									<div class="col-lg-6" style="width: 45%;">
										<label for="inputUsername" class="col-md-4 ">创建日期 <span
											class='require'>*</span> </label>
										<div class="col-md-12">
											<div class="input-icon">
												<input id="createTime" disabled="disabled" type="text"
													class="form-control" />
											</div>
										</div>
									</div>
								</div>
								<div class="row" style=" margin:20px 0px 0 0px;">
									<div class="col-lg-8" style="width: 92%">
										<label for="inputUsername" class="col-md-4">个性签名 <span
											class='require'></span> </label>
										<div class="col-md-12">
											<div class="input-icon">
												<textarea id="signature" rows="3" cols="20"
													class="form-control"></textarea>
											</div>
										</div>
									</div>
								</div>
								<div class="row" style=" margin:10px 0px 0px 0px;">
										<div class="col-lg-8" style="width: 92%">
										<div class="col-md-12">
											<button type="button" style="float: right;"
												class="btn btn-primary btn-blue"
												onclick="Page()">保&nbsp;存</button>
										</div>
									</div>
								</div>
								<input id="id" type="hidden" class="form-control" />
								</div>
							</form>
						</div>
					</div>
				</div>

			</div>
		</div>
	</div>


	<!--END CONTENT-->
</div>


<?} ?>
<script>
/*function getCookie() {
		var cookieval = document.cookie;
		var ca = document.cookie.split(';');
		for ( var i = 0; i < ca.length; i++) {
			var c = ca[i].trim();
			var arr=ca[i].split("=");
			if(arr.length==2){
				cookiename = arr[0].trim();
				var cookieValue = arr[1].trim();
				if ("userId"== cookiename){
					return cookieValue;
				}
			}
		}
		return "";
	}
	var index1 = getCookie();*/
	$(function() {
			$("#username").attr("disabled", "true");
			$("#mima").html("");
			demo1();
	});
	
	function Page() {
		if ($.trim($("#username").val()).length < 1) {
			alert('用户名不能为空！');
			return null;
		}
		if ($.trim($("#nickname").val()).length < 1) {
			alert('昵称不能为空！');
			return null;
		}
		var telephonetext=$.trim($("#telephone").val()); //    
       	var telephonere =/^[0-9]{11}$/;
		if (!telephonere.test(telephonetext)) {
			alert('手机号格式不正确！');
			return null;
		}
		if ($.trim($("#address").val()).length < 1) {
			alert('地址不能为空！');
			return null;
		}
	   	var text=$.trim($("#email").val()); //    
       	var re =/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
		if (!re.test(text)) {
			alert('邮箱格式不正确！');
			return null;
		}
		if ($.trim($("#parentClassid").val()).length < 1 || $("#parentClassid").val()==0) {
			alert('请选择部门！');
			return null;
		} 	
		if ($.trim($("#userGroupId").val()).length < 1 || $("#userGroupId").val()==0) {
			alert('请选择用户组！');
			return null;
		} 

		$.ajax({
			type : "post",
			url : "./userAddandUpdate.do",
			data : {
				"id" : -1,
				"username" : $("#username").val(),
				"password" : $("#password").val(),
				"nickname" : $("#nickname").val(),
				"telephone" : $("#telephone").val(),
				"address" : $("#address").val(),
				"email" : $("#email").val(),
				"departmentId" : $("#parentClassid").val(),
				"createTime" : $("#createTime").val(),
				"userPid" : $("#userPid").val(),
				"signature" : $("#signature").val(),
				"userGroupId" : $("#userGroupId").val(),
				"status" : $("#status").val()
			},
			dataType : "json",
			async : false,
			success : function(data) {
				layer.msg('保存成功');
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	function demo1() {
		$.getJSON('./userfindone.do', {
			id : -1
		//向服务端传的参数，此处只是演示
		}, function(res) {
			//此处仅仅是为了演示变化的内容
			$("#username").val(res[0].username);
			$("#nickname").val(res[0].nickname);
			$("#telephone").val(res[0].telephone);
			$("#address").val(res[0].address);
			$("#email").val(res[0].email);
			$("#parentclassname").val(res[0].departmentName);
			$("#parentClassid").val(res[0].departmentId);
			$("#createTime").val(res[0].createTime);
			$("#signature").val(res[0].signature);
			$("#userGroupName").val(res[0].userGroupName);
			$("#userGroupId").val(res[0].userGroupId);
			$("#status").val(res[0].status);
		});
	};
	function newdate() {
		$.getJSON('./newDate.do', {},
				function(res) {
					$("#createTime").val(res.date);
				});
	};
	function onPanduan(name) {

		$.ajax({
			type : "post",
			url : "./UserPanDuan.do",
			data : {
				"username" : name
			},
			dataType : "json",
			async : false,
			success : function(data) {
				if (data[0].tishi == 0) {
					alert("用户名不能重复");
					$("#username").val("");
				}
			}
		});
	}
	//选择父类
	function saveclassZTree() {
		layer.open({
			type : 2,
			area : [ '360px', '400px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			move : false,
			title:"部门选择",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["user-editSave-department-zTree.html", 'no'],
			yes : function(index,layer) {		
			   var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			  			  iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	}
	function saveGroupZTree() {
		layer.open({
			type : 2,
			area : [ '360px', '400px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			move : false,
			title:"用户组选择",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["user-editSave-userGroup-zTree.html", 'no'],
			yes : function(index,layer) {		
			   var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			  			  iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	}
</script>